var xmlHttp; 

function createXMLRequest(){
	if(window.ActiveXObject){
		xmlHttp=new ActiveXObject("Microsoft.XMLHttp");
	} else if(window.XMLHttpRequest){
		xmlHttp=new XMLHttpRequest();
	}
}

//发布话题
function publish(group){   
	createXMLRequest();       
	var title=document.getElementById("title").value;
	var editor0=document.getElementById("editor").innerHTML;
	if (editor0==""){
		alert("请输入话题内容！！！");
		return;
	} 
	if (title==""){
		alert("请输入题目内容！！！");
		return;
	} 
	var editor1=editor0.replace(/(&nbsp;)/ig," ");
	var editor2=editor1.replace(/\+/g,"*");
	var editor3=editor2.replace(/\s/ig,"{"); 
	var editor=editor3.replace(/\;/g,"}");      
	//alert(editor)    
	xmlHttp.open("POST","/groups/topic/publish/");
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange=handleStateChange;
	xmlHttp.send('group='+group+"&title="+title+"&editor="+editor); 
}

function handleStateChange(e){
	if(xmlHttp.readyState==4 && xmlHttp.status==200){
		if(isNaN(xmlHttp.responseText)){
			e.preventDefault();
    			$.scojs_message('服务器出错啦～ ：）', $.scojs_message.TYPE_ERROR);
		} else {
			window.location="/groups/topic/"+xmlHttp.responseText;
		}
	} else {
		//alert(xmlHttp.responseText)
		e.preventDefault();
    		$.scojs_message('服务器有小怪兽在捣乱～我们正在尽力捕捉～ ：）', $.scojs_message.TYPE_ERROR);
	}
}
